package com.example.my_invitation_service.controllers;

import com.example.my_invitation_service.entity.Domainname;
import com.example.my_invitation_service.services.DomainnameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@RestController
@RequestMapping(("/Domainname"))
public class DomainnameControllers {

    @Autowired
    private DomainnameService domainnameService;

    @GetMapping("/getActive")
    public Map<String, Object> getDomainnameByActive(int active){

        Map<String,Object> map = null;
        Optional<Domainname> op = Optional.ofNullable(domainnameService.getActive(active));
         if(op.isPresent()){
            map = new HashMap<>();
            map.put("code",200);
            map.put("result",op.get());
         }else{
             map = new HashMap<>();
             map.put("code",500);
         }

        return map;
    }
}
